﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;

namespace BulldogCMS.Core.Storage.DataTypes
{
    public class RichTextField : BaseDataType
    {
        public string Value
        {
            get;
            set;
        }

        public override System.Xml.Linq.XElement ToXElement()
        {
            XElement field = new XElement("field");
            field.SetAttributeOrLeaveEmpty("type", this.GetType().FullName);
            field.SetAttributeOrLeaveEmpty("name", this.Name);
            field.SetElementValue("value", this.Value);
            return field;
        }

        public override void LoadFromXElement(XElement el)
        {
            string type = el.GetAttributeValue<string>("type");
            string value = el.GetElementValue<string>("value");
            this.Name = el.GetAttributeValue<string>("name");

            if (this.GetType().FullName == type)
            {
                this.Value = value;
            }
            else
            {
                throw new ApplicationException("Type of field is different from loaded one -> Uncompatible types");
            }
        }

        public override XElement GetMetadata()
        {
            throw new NotImplementedException();
        }

        public override dynamic ToDynamicObject()
        {
            throw new NotImplementedException();
        }

        public override void LoadFromDynamicObject(dynamic obj)
        {
            throw new NotImplementedException();
        }
    }
}